using GameConfig.item;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace GameLogic
{
    public class Item : MonoBehaviour
    {
        public int itemID;

        private SpriteRenderer spriteRenderer;
        private BoxCollider2D coll;
        public ItemTb itemDetails;

        private void Awake()
        {
            spriteRenderer = GetComponentInChildren<SpriteRenderer>();
            coll = GetComponent<BoxCollider2D>();
        }

        private void Start()
        {
            if (itemID != 0)
            {
                Init(itemID);
            }
        }

        public void Init(int ID)
        {
            itemID = ID;

            //Inventory获得当前数据
            itemDetails = InventoryManager.Instance.GetItemDetails(itemID);

            if (itemDetails != null)
            {
                spriteRenderer.sprite =  itemDetails.ItemOnWorldSprite != null ? GameModule.Resource.LoadAsset<Sprite>(itemDetails.ItemOnWorldSprite) : GameModule.Resource.LoadAsset<Sprite>(itemDetails.ItemIcon);
                Vector2 newSize = new Vector2(spriteRenderer.sprite.bounds.size.x, spriteRenderer.sprite.bounds.size.y);
                coll.size = newSize;
                coll.offset = new Vector2(0, spriteRenderer.sprite.bounds.center.y);
            }

            //if (itemDetails.itemType == ItemType.ReapableScenery)
            //{
            //    gameObject.AddComponent<ReapItem>();
            //    gameObject.GetComponent<ReapItem>().InitCropData(itemDetails.itemID);
            //    gameObject.AddComponent<ItemInteractive>();
            //}
        }
    }
}